import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "../components/Home.vue"
import Login from "../components/login.vue"
import Welcome from "../components/Welcome.vue"
import Depts from "../components/depts.vue"
import Unauth from "../components/unauth.vue"
import Menu from "../components/menu.vue"
import Role from "../components/role.vue"
import AddPutOn from '../components/AddputOn.vue'
import PutOnManage from '../components/putOnManage.vue'
import Inventory from '../components/inventory.vue'
import User from '../components/user.vue'
import InventoryManage from '../components/inventoryManage.vue'
import Move from '../components/move.vue'
import MoveManage from '../components/moveManage.vue'
import Allocation from '../components/allocation.vue'
import AllocationManage from '../components/allocationManage.vue'
import Purchase from '../components/purchase.vue'
import Receive from '../components/receive.vue'
import ReceiveManage from '../components/receiveManage.vue'
import Warehousing from '../components/warehousing.vue'
import WarehousingManage from '../components/warehousingManage.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/login"
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect:'/welcome',
    children:[
      {path:'/welcome',component:Welcome},
      {path:'/dept/list',component:Depts},
      {path:'/unauth',component:Unauth},
      {path:'/menu',component:Menu},
      {path:'/role',component:Role},
      { path: '/puton/add',component: AddPutOn},
      { path: '/puton/manage',component: PutOnManage},
      { path: '/inventory/add',component: Inventory},
      { path: '/mgr',component: User},
      { path: '/inventory',component: InventoryManage},
      { path: '/move/add',component: Move},
      { path: '/move',component: MoveManage},
      { path: '/allocation/add',component: Allocation},
      { path: '/allocation',component: AllocationManage},
      { path: '/purchase',component: Purchase},
      { path: '/receive/add',component: Receive},
      { path: '/receive',component: ReceiveManage},
      { path: '/warehousing/add',component: Warehousing},
      { path: '/warehousing',component: WarehousingManage},
    ]
  },
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.path==='/login') return next();

  let token=window.sessionStorage.getItem("token");
  if(!token) return next("/login")

  next();
})

export default router
